package com.marveal.rabbit.producer.autoconfigure;

import com.marveal.rabbit.producer.broker.ProducerClient;
import com.marveal.rabbit.producer.broker.RabbitBroker;
import com.marveal.rabbit.producer.broker.RabbitBrokerImpl;
import com.marveal.rabbit.producer.broker.RabbitTemplateContainer;
import com.marveal.rabbit.producer.config.database.*;
import com.marveal.rabbit.producer.service.MessageStoreService;
import com.marveal.rabbit.producer.task.RetryMessageDataflowJob;
import com.marveal.rabbit.task.annotation.EnableElasticJob;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * $RabbitProducerAutoConfiguration 自动装配
 */
@EnableElasticJob
@Configuration
@Import(value = {
        RabbitProducerDataSourceConfiguration.class,
        RabbitProducerMyBatisConfiguration.class,
        RabbitProducerMybatisMapperScannerConfig.class,
        BrokerMessageConfiguration.class,
})
public class RabbitProducerAutoConfiguration {
    @Bean
    public MessageStoreService messageStoreService() {
        return new MessageStoreService();
    }

    @Bean
    public ProducerClient producerClient(RabbitBroker rabbitBroker) {
        return new ProducerClient(rabbitBroker);
    }

    @Bean
    public RabbitTemplateContainer rabbitTemplateContainer(MessageStoreService messageStoreService) {
        return new RabbitTemplateContainer(messageStoreService);
    }

    @Bean
    public RabbitBrokerImpl rabbitBroker(RabbitTemplateContainer rabbitTemplateContainer, MessageStoreService messageStoreService) {
        return new RabbitBrokerImpl(rabbitTemplateContainer, messageStoreService);
    }

    @Bean
    public RetryMessageDataflowJob retryMessageDataflowJob(MessageStoreService messageStoreService, RabbitBroker rabbitBroker) {
        return new RetryMessageDataflowJob(messageStoreService, rabbitBroker);
    }

}
